package net.kosev.battleships.adapters;

import net.kosev.battleships.model.Board;
import android.content.Context;
import android.widget.BaseAdapter;

/**
 * Base Image Adapter for grid boards
 * 
 * @author Nikola
 *
 */
public abstract class BoardAdapter extends BaseAdapter {
	
	/**
	 * Activity context
	 */
	protected Context mContext = null;
	
	/**
	 * Board fields array
	 */
	protected int[][] mFields = null;

	/**
	 * Constructor
	 * 
	 * @param context	Activity context
	 * @param fields	Board fields array
	 */
	public BoardAdapter(Context context, int[][] fields) {
		mContext = context;
		mFields = fields;
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getCount()
	 */
	public int getCount() {
		return Board.SIZE * Board.SIZE;
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getItem(int)
	 */
	public Object getItem(int position) {
		return mFields[position / Board.SIZE][position % Board.SIZE];
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getItemId(int)
	 */
	public long getItemId(int position) {
		return position;
	}

}
